const Service = require('egg').Service

class LoginService extends Service {
  async login() {
    const { username, password } = this.ctx.request.body
    return this.ctx.model.User.findOne({
      where: {
        username,
        password
      }
    })
  }

  async register() {
    const { username, password } = this.ctx.request.body
    const user = await this.ctx.model.User.findOne({
      where: {
        username
      }
    })
    if (user) {
      return '此用户已注册，请直接登录'
    }
    return this.ctx.model.User.create({ username, password })
  }

  async logout() {}
}

module.exports = LoginService
